const fs=require('fs');

module.exports=async url=>{
    let view;
    switch(url){
        case '/':
            view='index.html';
            break;
        case '/index':
            view='index.html';
            break;
        case '/todo':
            view='todo.html';
            break;
        default:
            view='404.html'
            break;
    }
    return await render(view)
};

function render(view) {
    return new Promise((resolve,reject)=>{
        fs.readFile(__dirname+'/views/'+view,'utf8',(err,html)=>{
            console.log('ERR:',err);
            if(err)return reject(err);
            resolve(html);
        });
    });
}